package tripx.user;

/**
 * The User Service Wrapper
 * 
 * @author zhb
 * 
 */
public class UserServiceWrapper {

	private UserService service;

	public UserServiceWrapper() {
		service = new UserService();
	}

	/**
	 * check whether this user is exist in the database.
	 * 
	 * @param uname
	 * @param upass
	 * @return
	 */
	public boolean checkUser(String uname, String upass) {
		String user = service.query("getUserByNamePass", uname, upass);
		if (user == null) {
			return false;
		}
		return !user.equals("[]");
	}

	/**
	 * add a new user to the database.
	 * 
	 * @param uname
	 * @param upass
	 * @return
	 */
	public boolean addUser(String uname, String upass) {
		String user = service.query("getUserByName", uname);
		// not exist
		if (user.equals("[]")) {
			DbUser dbUser = new DbUser(uname, upass);
			return service.addUser(dbUser);
		} else {
			return false;
		}
	}
}
